#include "graphics.h"
#include "globals.h"
#include <SDL.h>
#include <SDL_image.h>

Graphics::Graphics()
{
	SDL_CreateWindowAndRenderer(Globals::SCREEN_WIDTH, Globals::SCREEN_HEIGHT, 0, &this->Win, &this->Ren);
	SDL_SetWindowTitle(this->Win, "Platformer");
}

Graphics::~Graphics()
{
	SDL_DestroyWindow(this->Win);
	SDL_DestroyRenderer(this->Ren);
}

SDL_Surface* Graphics::LoadImage(const std::string &FilePath)
{
	if (this->SpriteSheets.count(FilePath) == 0)
	{
		this->SpriteSheets[FilePath] = IMG_Load(FilePath.c_str());
	}
	return this->SpriteSheets[FilePath];
}

void Graphics::BlitSurface(SDL_Texture* Texture, SDL_Rect* SourceRectangle, SDL_Rect* DestinationRectangle, int Angle)
{
	SDL_RenderCopyEx(this->Ren, Texture, SourceRectangle, DestinationRectangle, Angle, NULL, SDL_RendererFlip::SDL_FLIP_NONE);
}

void Graphics::BlitSurface(SDL_Texture* Texture, SDL_Rect* SourceRectangle, SDL_Rect* DestinationRectangle, int Angle, SDL_Point* Center, SDL_RendererFlip SRL)
{
	SDL_RenderCopyEx(this->Ren, Texture, SourceRectangle, DestinationRectangle, Angle, Center, SRL);
}

void Graphics::Flip()
{
	SDL_RenderPresent(this->Ren);
}

void Graphics::Clear()
{
	SDL_SetRenderDrawColor(this->Ren, 0, 0, 0, 255);
	SDL_RenderClear(this->Ren);
}

SDL_Renderer* Graphics::GetRenderer() const
{
	return this->Ren;
}
